using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using Betfair.Api;
using Betfair.Api.Types;
using Bull.Core;

namespace Bull.Plugins.Market.ViewModels
{
    public sealed class EventViewModel : ViewModelBase
    {
        private ICommand _eventTypeSelectCommand;

        public int Id { get; private set; }
        public string Name { get; private set; }
        public ICommand EventTypeSelectedCommand { get
        {
            return _eventTypeSelectCommand ?? (_eventTypeSelectCommand = new DelegateCommand(async () =>
            {
                var markets = await IoC.Container.BetfairProxy.GetMarkets(IdGenerator.Instance.GetId(),
                        new Params().SetFilter(new Filter().SetEventId(Id))
                            .SetMaxResult(200)
                            .SetMarketProjection(MarketProjection.EVENT)
                            .SetMarketProjection(MarketProjection.EVENT_TYPE)
                            .SetMarketProjection(MarketProjection.MARKET_DESCRIPTION)
                            .SetMarketProjection(MarketProjection.RUNNER_DESCRIPTION));
                if (markets.ResponseType != ResponseType.OK) return;

                
                Markets = new ObservableCollection<MarketCatalogueViewModel>(markets.Result.Select(market => new MarketCatalogueViewModel(market)));
                OnPropertyChanged("Markets");
            }));
        } }
        public ObservableCollection<MarketCatalogueViewModel> Markets { get; private set; }

        public EventViewModel(Event evt) {
            Id = evt.Id;
            Name = evt.Name;
        }

    }
}